<script>

</script>
<template>
  <div id="app" >
<!--    基础信息-->
    <div class="title">
      <h2><b>基础信息</b></h2>
      <el-form ref="form" :model="form" label-width="80px" inline>

        <el-form-item label="客户编码" prop="customerID" class="input">
          <el-input v-model="form.customerID" placeholder="请输入客户名称" />
        </el-form-item>

        <el-form-item label="客户名称" prop="customerName" class="">
          <el-select v-model="form.customerName" placeholder="请选择" clearable>
            <el-option label="七尾云科技有限公司" value="七尾云科技有限公司"></el-option>
            <el-option label="石矿公司" value="石矿公司"></el-option>
            <el-option label="三只羊集团" value="三只羊集团"></el-option>
            <el-option label="七个人" value="七个人"></el-option>
            <el-option label="无忧传媒" value="无忧传媒"></el-option>
            <el-option label="河南物流有限公司" value="河南物流有限公司"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属行业" prop="Industry">S
<!--          <el-cascader-->
<!--            v-model="value"-->
<!--            :options="options"-->
<!--            @change="handleChange" clearable>-->
<!--          </el-cascader>-->

          <el-select v-model="form.industry" placeholder="请选择" clearable>
            <el-option label="食品" value="食品"></el-option>
            <el-option label="医疗" value="医疗"></el-option>
            <el-option label="农业" value="农业"></el-option>
            <el-option label="冶金" value="冶金"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="客户级别">
          <el-select v-model="form.customerLevel" placeholder="请选择" clearable>
            <el-option label="普通客户" value="普通客户"></el-option>
            <el-option label="VIP1" value="VIP1"></el-option>
            <el-option label="VIP2" value="VIP2"></el-option>
            <el-option label="VIP3" value="VIP3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户标签">
          <el-select v-model="form.customerTags" placeholder="请选择" clearable>
            <el-option label="标签一" value="标签一"></el-option>
            <el-option label="标签二" value="标签二"></el-option>
            <el-option label="标签三" value="标签三"></el-option>
            <el-option label="标签四" value="标签四"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="区域" prop="region">
<!--          <el-cascader-->
<!--            v-model="value1"-->
<!--            :options="options1"-->
<!--            @change="handleChange" clearable>-->
<!--          </el-cascader>-->
          <el-select v-model="form.region" placeholder="请选择" clearable>
            <el-option label="四川省" value="四川省"></el-option>
            <el-option label="广东省" value="广东省"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="公司地址" prop="companyAddress">
          <el-input v-model="form.companyAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="邮编" prop="zipCode">
          <el-input v-model="form.zipCode" placeholder="请输入邮编" />
        </el-form-item>
        <el-form-item label="备注信息" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="客户状态">-->
<!--          <el-switch v-model="form.customerStatus"></el-switch>-->
<!--        </el-form-item>-->
      </el-form>


    </div>


<!--    联系人信息-->
    <div class="lian">
      <h2><b>联系人信息</b></h2>
      <el-form ref="form" :model="form" label-width="80px" inline>
        <el-form-item label="姓名" prop="ContactName">
          <el-input v-model="form.contactName" placeholder="请输入姓名" />
        </el-form-item>

        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
        </el-form-item>

        <el-form-item label="部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门" />
        </el-form-item>

        <el-form-item label="职位" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位" />
        </el-form-item>

        <el-form-item label="E-mail" prop="email">
          <el-input v-model="form.email" placeholder="请输入E-mail" />
        </el-form-item>

        <el-form-item label="qq" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入QQ" />
        </el-form-item>
      </el-form>

    </div>

<!--    财务信息-->
    <div class="cai">

      <h2><b>财务信息</b></h2>

      <el-form ref="form" :model="form" label-width="80px" inline>
      <el-form-item label="发票抬头" prop="invoiceTitle">
        <el-input v-model="form.invoiceTitle" placeholder="请输入发票抬头" />
      </el-form-item>

      <el-form-item label="纳税人识别号" prop="taxpayerID">
        <el-input v-model="form.taxpayerID" placeholder="请输入纳税人识别号" />
      </el-form-item>

      <el-form-item label="开户行" prop="bankName">
        <el-input v-model="form.bankName" placeholder="请输入开户行" />
      </el-form-item>

      <el-form-item label="开户名称" prop="accountName">
        <el-input v-model="form.accountName" placeholder="请输入开户名称" />
      </el-form-item>

      <el-form-item label="银行账号" prop="bankAccount">
        <el-input v-model="form.bankAccount" placeholder="请输入银行账号" />
      </el-form-item>
      </el-form>
    </div>

    <div class="bao">
      <el-button type="primary" @click="submitForm()">保存</el-button>
      <el-button @click="cancel()">取消</el-button>
    </div>
  </div>


</template>

<style>
.title {
  margin-left: 50px;
}
.lian{
  margin-left: 50px;
}
.cai{
  margin-left: 50px;
}
.bao{
  text-align: right;
  padding: 100px;
}

.input {
  width: 300px;
}
</style>

<script>
// import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from "@/api/customer/customer";

import {addCustomer, getCustomer, updateCustomer} from "@/api/customer/customer";

export default {
  data() {
    return {
      form: {},

      rules: {
        customerName: [
          {required: true, message: "客户名称不能为空", trigger: "blur"}
        ],
        phoneNumber: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
      }
    };
  },
  created() {
    // this.getList();
    console.log( this.$route.query.id+"....."+(this.$route.query.id!==undefined))
    if(this.$route.query.id!==undefined){
      this.findCustomer();
    }

  },
  methods: {
    findCustomer(){
      var id = this.$route.query.id;
      getCustomer(id).then(response => {
        this.form = response.data;
      });
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCustomer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.options=response.data;
              // this.open = false;
              // this.getList();
              this.$router.push({ path: '/customerindex' })
            });
          } else {
            addCustomer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              // this.open = false;
              // this.getList();
              this.$router.push({ path: '/customerindex' })
            });
          }
        }
      });
    },

    // add() {
    //   // 发送 POST 请求到后端
    //   this.$axios.post('/api/saveCustomer', this.form)
    //     .then(response => {
    //       console.log('保存成功:', response.data);
    //       // 可以在这里处理成功后的逻辑，例如显示提示信息或重置表单
    //     })
    //     .catch(error => {
    //       console.error('保存失败:', error);
    //       // 可以在这里处理错误，例如显示错误提示
    //     });
    // },
    cancel(){
      this.$router.push({ path: '/qu' })
    }
  }
}

</script>

